<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!--返回错误信息-->
<?php echo validation_errors(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    $title = [
        'title' => '招标详情',
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    <!--    头部   侧边菜单-->
    <?php $this->load->view('/admin/common/bodyLeft'); ?>
    <script type="text/javascript">
    	$(".js-sidebar-nav>li:nth-child(12)>ul").show(80);
    	$(".js-sidebar-nav>li:nth-child(12)>a>span").addClass("sidebar-nav-sub-ico-rotate");
    	$(".js-sidebar-nav>li:nth-child(12)>ul>li:nth-child(3)>a").addClass("active");
    </script>
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
			<div class="row-content am-cf">
				<div class="row">
					<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
						<div class="widget am-cf">
							<div class="widget-head am-cf">
								<div class="widget-title  am-cf">
									<ol class="am-breadcrumb am-breadcrumb-slash">
                    <li><a href="/admin/bidding/index?page=1">招投标管理</a></li>
										<li><a href="/admin/bidding/checkList?page=1">招标审核</a></li>
                    <li class="am-active">招标详情</li>
									</ol>
								</div>
							</div>
							<form class="am-form am-text-sm" id="submitForm">
								<div class="widget-body am-fr">
									<div class="tpl-table-black-operation">
										<a href="javascript:void(0);" class="tpl-table-black-operation-del">
											基本信息
										</a>
									</div>

									<div style="margin-top: 20px">
										<div class="am-g">
											<!-- Row start -->
											<div class="am-u-sm-12">
												<div class="am-g-fixed am-cf">
													<div class="am-u-md-6">														
														<div class="am-form-group">
															<div class="am-g">
																<label class="am-u-md-2 am-md-text-right am-padding-left-0 " for="projectid">招标项目编号</label>
																<div class="am-u-md-10">
																	<input type="text" name="code" value="<?php echo $list['code'] ?>" id="projectid" readonly>
																</div>
															</div>
														</div>

														<div class="am-form-group">
															<div class="am-g">
																<label class="am-u-md-2 am-md-text-right am-padding-left-0 " for="name">项目名称</label>
																<div class="am-u-md-10">
																	<input type="text" name="name" value="<?php echo $list['name'] ?>" id="name" placeholder="请填写项目名称" disabled="disabled">
																</div>
																
															</div>
														</div>

														<div class="am-form-group">
															<div class="am-g">
																<label class="am-u-md-2 am-md-text-right am-padding-left-0 " for="time">发布时间</label>
																<div class="am-u-md-10">
																	<input type="date"  value="<?php echo date('Y-m-d',$list['createTime']) ?>" id="time" disabled="disabled">
																</div>
															</div>
														</div>
														
													</div>

													<div class="am-u-md-6">
                                                        <?php
                                                        if($list['needCode']){
                                                            echo '<div class="am-form-group">
															<div class="am-g">
																<label class="am-u-md-2 am-md-text-right am-padding-left-0 " for="xqdid">需求单号</label>
                                                        		<div class="am-u-md-10">
																	<input type="text" name="needCode" value="'.$list['needCode'].'" id="xqdid" disabled="disabled">
                                                        		</div>

																
															</div>
														</div>';
                                                        }else{
                                                            echo '';

                                                        }
                                                        ?>
														<div class="am-form-group">
															<div class="am-g">
																<label class="am-u-md-2 am-md-text-right am-padding-left-0 " for="timelimit">有效时间</label>
                                                        		<div class="am-u-md-10">
                                                        			<input type="tel" class="am-u-md-10 form-control" name="validTime" value="<?php echo $list['validTime'] ?>" id="timelimit" disabled="disabled">
                                                        		</div>
															</div>
														</div>
	
												    <div class="am-form-group am-form-file">
													      <label class="am-u-sm-2 am-md-text-right am-padding-left-0 " for="file-2">项目附件</label>
													      <div class="am-inline-block am-u-sm-10">
	                                                          <?php
	                                                          if($list['projectImg']){
	                                                              echo '<a href="'.$list['projectImg'].'" download="项目附件">下载</a>';
	                                                          }else{
	                                                              echo '<a href="javascript:;">未上传</a>';

	                                                          }
	                                                          ?>
													      </div>
												    </div>
													</div>
													<div class="am-form-group  am-u-md-12">
															<label class="am-u-md-1  am-md-text-right am-padding-left-0">所在地区</label>
															<div class="am-u-md-3 am-u-end">
                                                            	<?php echo $list['address'] ?>
															</div>
													</div>
													
													<div class="am-form-group  am-u-md-12">
														<div class="am-g">
															<label class="am-u-md-2">预选供应商</label>
															<div class="am-u-md-10">																															
																<table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
																  <thead>
																	  <tr>
																	    <th>供应商编号</th>
																	    <th>供应商名称</th>
																	    <th>供应商地址</th>
																	  </tr>
																  </thead>
																  <tbody>
                                                                  <?php
                                                                        foreach ($list['supplierInfoAll'] as $k=>$v){
                                                                            echo '<tr>
																  		<td>'.$v['id'].'</td>
																  		<td>'.$v['name'].'</td>
																  		<td>'.$v['address'].'</td>
																  	</tr>';
                                                                        }
                                                                  ?>

																  </tbody>
																</table>																
															</div>
														</div>
													</div>											
													
													<div class="am-form-group  am-u-md-12">
														<div class="am-g">
															<label class="am-u-md-2">项目简介</label>
															<div class="am-u-md-10">
                                                                <?php
                                                                    echo trim($list['synopsis']);
                                                                ?>
															</div>	
														</div>
													</div>														
												</div>
											</div>
										</div>										
									</div>
									<div class="tpl-table-black-operation">
										<hr />
										<a href="javascript:void(0);" class="tpl-table-black-operation-del">其他信息</a>
									</div>
									<br />
									
									<div class="am-form-group am-u-md-12 am-cf">
								    <label for="doc-ipt-3" class="am-u-sm-1 am-form-label">需要的资质</label>
								    <div class="am-u-sm-3 am-u-end">
								      	<div class="am-checkbox">
	                                        <?php
	                                        if($list['needData']){
	                                            echo '<label><input type="checkbox" class="needData-c" value="营业执照" disabled="disabled" checked="checked"/>营业执照</label>';
	                                        }else{
	                                            echo '<label><input type="checkbox" class="needData-c" value="营业执照" disabled="disabled" />营业执照</label>';
	                                        }
	                                        ?>
								      	</div>
								    </div>
								  </div>
								  
								  <div class="am-form-group  am-u-md-12">
								    <label for="bzmoney" class="am-u-sm-1 am-form-label ">需要交纳保证金</label>
								    
								    <div class="am-u-md-3 am-input-group am-u-end">
										<input type="number" id="bzmoney" name="needAmount" value="<?php echo $list['needAmount'] ?>" class="am-form-field" disabled="disabled"> 
									  	<span class="am-input-group-label">元</span>
									</div>
								  </div>
								  
								  <div class="am-form-group  am-u-md-12">
								    <label for="contacts" class="am-u-sm-1 am-form-label ">联系人</label>
								    <div class="am-u-md-3 am-u-end">
								    	<input type="text"  name="contactMan" value="<?php echo $list['contactMan'] ?>" class="form-control" disabled="disabled">
								    </div>
								  </div>
								  
								  <div class="am-form-group  am-u-md-12">
								    <label for="phone" class="am-u-sm-1 am-form-label ">联系电话</label>
								    <div class="am-u-md-3 am-u-end">
								    	<input type="tel"  name="phone" value="<?php echo $list['phone'] ?>" class="form-control" disabled="disabled">
								    </div>
								  </div>
								  

									
									<div class="tpl-table-black-operation  am-u-md-12">
										<hr />
										<a href="javascript:void(0);" class="tpl-table-black-operation-del">
											文件
										</a>
									</div>
									<br />
									
							    <div class="am-form-group am-form-file am-u-md-12">
							    	<br />
							      <label class="am-u-sm-1 am-form-label " for="file-2">标书文件</label>
									<div class="am-inline-block">
                                        <?php
                                            if($list['biddingFile']){
                                                echo '<a href="'.$list['biddingFile'].'" download="标书文件">下载</a>';
                                            }else{
                                                echo '<a href="javascript:;">未上传</a>';

                                            }
                                        ?>
							      </div>
							    </div>
							    <div class="am-form-group am-form-file am-u-md-12">
							      <label class="am-u-sm-1 am-form-label ">采购清单</label>
							      <div class="am-inline-block">
                                      <?php
                                      if($list['procurementImg']){
                                          echo '<a href="'.$list['procurementImg'].'" download="采购清单">下载</a>';
                                      }else{
                                          echo '<a href="javascript:;">未上传</a>';

                                      }
                                      ?>
                                  </div>
							    </div>
							    
									<div class="tpl-table-black-operation am-u-md-12">
										<hr />
										<a href="javascript:void(0);" class="tpl-table-black-operation-del">供应商资料</a>
									</div>	
									<div class="am-u-md-12 r_box">
								    <p class="am-u-md-12">
								    	预选供应商<span class="r_num"><?php echo $list['supplierNum'] ?></span>个&nbsp;&nbsp;&nbsp;&nbsp;
								    	已报名<span class="r_num"><?php echo $list['agree'] ?></span>个&nbsp;&nbsp;&nbsp;&nbsp;
								    	已拒绝<span class="r_num"><?php echo $list['refuse'] ?></span>个
								    </p>
<!--								    <p>资料提交<span class="r_num">--><?php //echo count($list['supplierInfo']) ?><!--</span>个</p>-->

								  </div>							    
							    <div class=" am-u-md-12 am-g-fixed">
							    	<div class="am-u-sm-6"> 
										<label class="am-u-sm-4 am-form-label" >选择供应商：</label>
										<select data-am-selected class="am-u-sm-8" id="supplier-select">
											<option value=""></option>
						                    <?php
						                        foreach ($list['supplierInfo'] as $k=>$v){
						                            echo '<option value="'.$v['id'].'" >'.$v['name'].'</option>';
						                        }
						                    ?>
										</select>
									</div>
									<div class="am-u-sm-6"> 
										<label class="am-u-sm-4 am-form-label">报价系数：</label>
										<div class="am-u-sm-8">
											<input type="text" class="form-control am-u-sm-8"  readonly="readonly" id="offerNum">
										</div>

									</div>

							    </div>
							    <div class="am-g-fixed">
							    	<div class="am-u-sm-12 gys-des">
									    <div class="am-form-group am-form-file am-u-md-12">
									      	<div class="tpl-table-black-operation">
												<br />
												<a href="javascript:void(0);" class="tpl-table-black-operation-del">
													报价单:
												</a>
											</div>
									    </div>
									    <div class="am-form-group am-form-file am-u-md-12">
									    	<label class="am-u-sm-2 am-form-label">报价单：</label>
									    	<div class="am-u-sm-10 bjFile">
									    		<!-- <span>竞标商品报价单.doc</span>  -->
                                               <span>未选择供应商</span>
                                               <!-- <a href="#" id="bjDownload" download="报价单">下载</a> -->
									    	</div>
									    </div>
									    <div class="am-form-group am-form-file am-u-md-12">
									      	<div class="tpl-table-black-operation">
												<br />
												<a href="javascript:void(0);" class="tpl-table-black-operation-del">
													资质单:
												</a>
											</div>
									    </div>
									    <div class="am-form-group am-form-file am-u-md-12 ">
									    	<label class="am-u-sm-2 am-form-label">营业执照：</label>
									    	<div class="am-u-sm-10 yyzzFile">
									    		<!-- <a href="#" id="yyzzDownload" download="营业执照">下载</a> -->
                                                <span>未选择供应商</span>

									    	</div>
									    </div>
									    <div class="am-form-group am-form-file am-u-md-12 ">
									    	<label class="am-u-sm-2 am-form-label">其他资质：</label>
									    	<div class="am-u-sm-10 otherFile">
									    		<!-- <a href="#" id="otherDownload" download="">下载</a> -->
                                                <span>未选择供应商</span>
									    	</div>
									    </div>
									    <div class="am-form-group am-form-file am-u-md-12">
									      	<div class="tpl-table-black-operation">
												<br />
												<a href="javascript:void(0);" class="tpl-table-black-operation-del">
													联系信息:
												</a>
											</div>
									    </div>
									    <div class="am-form-group am-u-md-12 ">
									    	<div class="am-form-group am-u-md-6">
											    <label for="contactMan" class="am-u-sm-3 am-form-label">联系人：</label>
											    <div class="am-u-sm-9">
											      <input type="text" class="form-control" id="contactMan"  readonly="readonly" >
											    </div>
												</div>
												<div class="am-form-group am-u-md-6">
												    <label  class="am-u-sm-3 am-form-label" for="phone">联系电话：</label>
												    <div class="am-u-sm-9">
												      <input type="text" class="form-control" id="phone"    readonly="readonly">
												    </div>
												</div>
									    </div>
									    <div class="am-form-group am-u-md-12 ">
									    	<div class="am-form-group am-u-md-6">
											    <label for="contactMan" class="am-u-sm-3 am-form-label">评分：</label>
											    <div class="am-u-sm-9">
											      	<input type="number" id="score" class="form-control" min="0" max="100" placeholder="0-100">
											    </div>
												</div>
									    </div>

								    </div>
							    </div>
							    
							    <div class="am-g-fixed">
											<div class="am-u-sm-12 btn-box">
                          <input type="button" value="提交" name="action" class="am-btn am-btn-primary tpl-btn-bg-color-success commit" style="width:150px;margin: 20px;">
                          <button onclick="back()" class="am-btn am-btn-primary tpl-btn-bg-color-success" style="width:150px;margin: 20px;"> 取消</button>	                                    
                 			</div>
                                        
									</div>
									
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<!--弹出框-->
<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">提示</div>
    <div id="pop-up-content" class="am-modal-bd"></div>
    <div class="am-modal-footer">
      <span class="am-modal-btn">确定</span>
    </div>
  </div>
</div>

<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>

<script type="text/javascript">
	

		var biddingCheckId = <?php echo $list['id'] ?>;  // 代办id				
		var checkId = <?php echo $_GET['checkId'] ?>;
		var checkUser = "<?php echo $_COOKIE['nickname'] ?>";		
		var arrSup = <?php echo json_encode($list['supplierInfo'])?>;
		var supplierId;
		var supplierName;
		var arrScore = [];
		for (var i = 0; i < arrSup.length; i++) {
			arrScore[i] = {
				"supplierId": arrSup[i].id, 
				"score": "", 
				"checkUser": checkUser, 
				"supplierName": arrSup[i].name
			}							
		}	
		
		// 选择供应商 下拉框
		$("#supplier-select").change(function() {			
			supplierId = $(this).val();
			supplierName = $(this).find("option:selected").text();
			postDataById(supplierId);
		});
		
		function postDataById(supplierId){
			$.ajax({
				url:"/admin/bidding/chooseSupplierFile",
	        data:{
	            biddingCheckId:biddingCheckId,
	            supplierId:supplierId
	        },
	        dataType:"json",
	        type:"post",
	        async:true,
	        success:function(data){
	        	console.log(data);
	        	var bjFile = data.bjFile;     		//报价单
	        	var offerNum = data.offerNum;		//报价系数
	        	var contactMan = data.contactMan;	//联系人
	        	var phone = data.phone;				//联系电话
	        	var yyzzFile = data.yyzzFile;       //营业执照
	        	var otherFile = data.otherFile;     //其他资质
            var downloadFile = "";
	        	var score = "";   //评分

	        	if(!bjFile){
            		downloadFile = '<a href="javascript:;">未上传</a>';
            		$(".bjFile").html(downloadFile);
            	}else{
            		downloadFile = '<a href="'+ bjFile +'" download="报价单">下载</a>';
            		$(".bjFile").html(downloadFile);
            	}

          	if(!yyzzFile){
          		downloadFile = '<a href="javascript:;" >未上传</a>';
          		$(".yyzzFile").html(downloadFile);
          	}else{
          		downloadFile = '<a href="'+ yyzzFile +'" download="营业执照">下载</a>';
          		$(".yyzzFile").html(downloadFile);
          	}

          	if(!otherFile){
          		downloadFile = '<a href="javascript:;" >未上传</a>';
          		$(".otherFile").html(downloadFile);
          	}else{
          		downloadFile = '<a href="'+ otherFile +'" download="其他资质">下载</a>';
          		$(".otherFile").html(downloadFile);
          	}

	        	$("#bjDownload").prop("href",bjFile);
	        	$("#offerNum").val(offerNum);
	        	$("#contactMan").val(contactMan);
	        	$("#phone").val(phone);
	        	
	        	for (var i = 0; i < arrScore.length; i++) {
	        		if (arrScore[i].supplierId == supplierId) {
	        			// 根据id找到对应供应商	        			
	        			score = (arrScore[i].score.length == 0 && data.score) ? data.score[0].score : arrScore[i].score;// 使用ajax数据 / 本地数据
	        			arrScore[i].score = score;
	        			break;
	        		}
	        	}
	        	$("#score").val(score);	        	
	        }
				});
		}
		
		// 评分输入框		
		$("#score").blur(function(){
			if (!supplierId) return;// 没有选供应商时
			var value = $.trim($("#score").val());
			if (value.length > 0) {
				value = value - 0;
				if (value < this.min - 0 || value > this.max - 0) {
					// 输入的数超出规定范围
					$("#pop-up-content").text("请输入" + this.min + "~" + this.max + "的评分");
					$("#my-alert").modal();
					$("#my-alert").on("closed.modal.amui", function() {
						$(this).focus();
					});					
				} else {
					// 输入的数合法, 记录下来
					for (var j = 0; j < arrSup.length; j++) {
						if (supplierId == arrScore[j].supplierId) {
							arrScore[j].score = value;
						}
					}
					console.log(arrScore);					
				}				
			}
		});

		// 提交
		var lockSubmit = false;
		$(".commit").click(function(){
			if(lockSubmit){
        return false;
      }
      lockSubmit =true;

			// 表单验证
			if(!supplierName){
				$("#pop-up-content").text("您还没有选择供应商");
				$("#my-alert").modal();
				lockSubmit = false;
				return;
			}
			if (arrScore.length == 0) {
				$("#pop-up-content").text("您还没有评分");
				$("#my-alert").modal();
				$("#my-alert").on("closed.modal.amui", function() {
					$("#score").focus();
				});
				lockSubmit = false;
				return;
			}

			console.log("数组:",arrScore);
			// 传送数据
			$.ajax({
				url:"/admin/bidding/score",
        data:{
          id: biddingCheckId,
          checkId: checkId,
          score: JSON.stringify(arrScore)
        },
        dataType:"json",
        type:"post",
        success:function(data){
					console.log("success",data);
					$("#pop-up-content").text("提交成功");
					$("#my-alert").modal();
					window.location.href = '/admin/check/index?page=1&type=2';
					lockSubmit = false;
      	},
      	error:function(a,b,c){
      		console.log("baocuo");
      		console.log(a);
      		console.log(b);
      		console.log(c);
      		lockSubmit = false;
      	}
			});
			
		});		
	
		
		
		

</script>

</body>

</html>